home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / Ang261Lib.lha / src / util.c < prev    next >
C/C++ Source or Header  |  1994-10-22  |  2KB  |  80 lines

  1. /*
  2.  * util.c: miscellanous utilities 
  3.  *
  4.  * Copyright (c) 1989 James E. Wilson 
  5.  *
  6.  * This software may be copied and distributed for educational, research, and
  7.  * not for profit purposes provided that this copyright and statement are
  8.  * included in all such copies. 
  9.  */
  10.  
  11. #include "constant.h"
  12. #include "config.h"
  13. #include "types.h"
  14. #include "externs.h"
  15.  
  16. /* For those systems that don't have stricmp. -hmj */
  17.  
  18. #if defined(NEEDS_STRICMP)
  19. int
  20. my_stricmp(c1,c2)        /* avoid namespace collision -CWS */
  21. const char *c1;
  22. const char *c2;
  23. {
  24.     char c3;
  25.     char c4;
  26.     
  27.     for(;;) {      
  28.     c3 = (islower(*c1)?toupper(*c1):*c1);
  29.     c4 = (islower(*c2)?toupper(*c2):*c2);
  30.     if (c3 < c4) return(-1);
  31.     if (c3 > c4) return(1);
  32.     if (c3 == '\0') return(0);
  33.     c1++;
  34.     c2++;
  35.     };
  36. }      
  37. #endif
  38.  
  39. #if defined(NEEDS_USLEEP)
  40. #include <stdio.h>
  41. #include <math.h>
  42. #include <signal.h>
  43. #include <errno.h>
  44. #include <sys/types.h>
  45. #include <sys/time.h>
  46.  
  47. /* for those systems that don't have usleep */
  48. /* grabbed from the inl netrek server -cba  */
  49.  
  50. int
  51. microsleep(microSeconds)
  52. unsigned long microSeconds;
  53. {
  54.     unsigned int        Seconds, uSec;
  55.     int                 nfds, readfds, writefds, exceptfds;
  56.     struct timeval      Timer;
  57.  
  58.     nfds = readfds = writefds = exceptfds = 0;
  59.     
  60.     if (microSeconds > (unsigned long)4000000) {
  61.     errno = ERANGE;           /* value out of range */
  62.     perror("usleep time out of range ( 0 -> 4000000 ) ");
  63.     return -1;
  64.     }
  65.     Seconds = microSeconds / (unsigned long)1000000;
  66.     uSec = microSeconds % (unsigned long)1000000;
  67.  
  68.     Timer.tv_sec = Seconds;
  69.     Timer.tv_usec = uSec;
  70.     if (select(nfds, &readfds, &writefds, &exceptfds, &Timer) < 0) {
  71.     if (errno != EINTR) {
  72.         perror("usleep (select) failed");
  73.         return -1;
  74.     }
  75.     }
  76.     return 0;
  77. }
  78.  
  79. #endif
  80.